package com.example.lock.zkLock;

import com.example.lock.Job;
import com.example.lock.OrderNoProvider;
import com.example.lock.redisLock.SimpleJedisClusterLock;

import java.util.concurrent.*;

public class TestZkLock {


    public static void main(String[] args) {
     /*   final ZkClientExt zkClientExt1 = new ZkClientExt("47.97.173.74:9555", 5000, 5000, new BytesPushThroughSerializer());
        final SimpleZookeeperLock zkLock1 = new SimpleZookeeperLock(zkClientExt1, "/Mutex");

        final ZkClientExt zkClientExt2 = new ZkClientExt("47.97.173.74:9555", 5000, 5000, new BytesPushThroughSerializer());
        final SimpleZookeeperLock zkLock2 = new SimpleZookeeperLock(zkClientExt2, "/Mutex");
*/
        //SimpleJedisLock jedisLock = new SimpleJedisLock();
        SimpleJedisClusterLock simpleJedisClusterLock = new SimpleJedisClusterLock();

        ArrayBlockingQueue queue = new ArrayBlockingQueue<Job>(10);
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(100, 100, 10, TimeUnit.MILLISECONDS, queue);
        final   CyclicBarrier cyclicBarrier = new CyclicBarrier(100, new Runnable() {
            public void run() {
                System.out.println("当前线程："+Thread.currentThread().getName());
                System.out.println("全部线程已准备reday============>");
                try {
                    Thread.sleep(3000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        OrderNoProvider orderNoProvider = new OrderNoProvider();
        Job job = new Job(orderNoProvider,cyclicBarrier , simpleJedisClusterLock);
        for(int i=1 ;i<=100;i++){
            threadPoolExecutor.execute(job);
        }
    }





}
